﻿<%@ page import="com.iot08.common.entity.app.BrokenScreenInsurance" %>
<%@ page import="java.util.Date" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<jsp:useBean id="dateValue" class="java.util.Date"/>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="<%=basePath%>">
    <!-- jsp文件头和头部 -->
    <%@ include file="../admin/top.jsp" %>
    <style>
        table tr td img {
            height: 25px;
            border-radius: 8%;
        }
    </style>
</head>
<body>
<div class="container-fluid" id="main-container">
    <div id="page-content" class="clearfix">
        <div class="row-fluid">
            <div class="row-fluid">
                <!-- 检索  -->
                <form action="brokenScreenInsurance/list" method="post" name="brokenScreenInsuranceForm" id="brokenScreenInsuranceForm">
                    <input type="hidden" name="menuId" value="${page.menuId}">
                    <table style="width: 50%">
                        <tr>
                            <td style="width: 32%">
                                   <span class="input-icon">
                                     <input style="margin-top: 0px;width: 85%" autocomplete="off" type="text"
                                            name="searchValue" value="${page.searchValue}" placeholder="碎屏险id"/>
                                   </span>
                            </td>
                            <td style="width: 32%">
                                   <span class="input-icon">
                                     <input style="margin-top: 0px;width: 85%" autocomplete="off" type="text"
                                            name="openid" value="${openid}" placeholder="用户id"/>
                                   </span>
                            </td>
                            <td style="width: 32%">
                                   <span class="input-icon">
                                     <input style="margin-top: 0px;width: 85%" autocomplete="off" type="text"
                                            name="checkCode" value="${checkCode}" placeholder="核销码"/>
                                   </span>
                            </td>
                            <td>
                            <td style="vertical-align:top;width: 20%">
                                <select class="chzn-select" name="status" data-values="${status}"
                                        data-placeholder="请选择碎屏险状态" style="vertical-align:top;width: 140px;">
                                    <option value="">选择碎屏险状态</option>
                                    <option value="1" <c:if test="${status == 1}">selected</c:if>>生效中</option>
                                    <option value="2" <c:if test="${status == 2}">selected</c:if>>已使用</option>
                                    <option value="3" <c:if test="${status == 3}">selected</c:if>>已过期</option>
                                    <option value="4" <c:if test="${status == 4}">selected</c:if>>已失效</option>
                                </select>
                            </td>
                            <td style="vertical-align:top;width: 8%">
                                <button class="btn btn-mini btn-light" onclick="search();" title="检索">
                                    <i id="nav-search-icon" class="icon-search"></i>
                                </button>
                            </td>
                        </tr>
                    </table>
                    <!-- 检索  -->
                    <table id="table_report" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>id</th>
                            <th>核销码</th>
                            <th>用户id</th>
                            <th>剩余次数</th>
                            <th>已使用次数</th>
                            <th>状态</th>
                            <th>有效开始时间</th>
                            <th>有效结束时间</th>
                            <th>创建时间</th>
                            <th>修改时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <!-- 开始循环 -->
                        <c:choose>
                            <c:when test="${not empty brokenScreenInsurances}">
                                <c:forEach items="${brokenScreenInsurances}" var="brokenScreenInsurance">
                                    <%
                                        // 只能通过 pageContext 获取 JSTL 变量
                                        Object obj = pageContext.findAttribute("brokenScreenInsurance");
                                        if (obj != null) {
                                            BrokenScreenInsurance bsi =  (BrokenScreenInsurance) obj;
                                            long startTs = bsi.getStartTime() * 1000L;
                                            long endTs = bsi.getEndTime() * 1000L;
                                            Date startDate = new Date(startTs);
                                            Date endDate = new Date(endTs);
                                            pageContext.setAttribute("startTimeDate", startDate);
                                            pageContext.setAttribute("endTimeDate", endDate);
                                        }
                                    %>
                                    <tr style="text-align: center">
                                        <td>${brokenScreenInsurance.id }</td>
                                        <td>${brokenScreenInsurance.checkCode}</td>
                                        <td>${brokenScreenInsurance.openid}</td>
                                        <td>${brokenScreenInsurance.num}</td>
                                        <td>${brokenScreenInsurance.useNum}</td>
                                        <td>
                                            <c:choose>
                                                <c:when test="${brokenScreenInsurance.status == 1}">
                                                    生效中
                                                </c:when>
                                                <c:when test="${brokenScreenInsurance.status == 2}">
                                                    已使用
                                                </c:when>
                                                <c:when test="${brokenScreenInsurance.status == 3}">
                                                    已过期
                                                </c:when>
                                                <c:when test="${brokenScreenInsurance.status == 4}">
                                                    已失效
                                                </c:when>
                                                <c:otherwise>
                                                    未知状态
                                                </c:otherwise>
                                            </c:choose>
                                        </td>

                                        <td>
                                            <fmt:formatDate value="${startTimeDate}" pattern="yyyy-MM-dd HH:mm:ss" />
                                        </td>
                                        <td>
                                            <fmt:formatDate value="${endTimeDate}" pattern="yyyy-MM-dd HH:mm:ss" />
                                        </td>
                                        <td>
                                            <fmt:formatDate value="${brokenScreenInsurance.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
                                        </td>
                                        <td>
                                            <fmt:formatDate value="${brokenScreenInsurance.updateTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
                                        </td>
                                        <td>
                                            <div class='hidden-phone visible-desktop btn-group'>
                                                <c:if test="${fn:contains(butSet, 'check') && brokenScreenInsurance.status == 1}">
                                                    <a class='btn btn-mini btn-danger' title="核销" onclick="operateDev('${brokenScreenInsurance.id}',0);">
                                                        核销
                                                    </a>
                                                </c:if>
                                                <c:if test="${fn:contains(butSet, 'unCheck') && brokenScreenInsurance.useNum > 0}">
                                                    <a class='btn btn-mini btn-danger' title="撤销核销" onclick="operateDev('${brokenScreenInsurance.id}',1);">
                                                        撤销核销
                                                    </a>
                                                </c:if>
                                            </div>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </c:when>
                            <c:otherwise>
                                <tr class="main_info">
                                    <td colspan="11" class="center">没有相关数据</td>
                                </tr>
                            </c:otherwise>
                        </c:choose>
                        </tbody>
                    </table>
                    <div class="page-header position-relative">
                        <table style="width:100%;">
                            <tr>
                                <td style="vertical-align:top;">
                                    <div class="pagination"
                                         style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div>
                                </td>
                            </tr>
                        </table>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 返回顶部  -->
<a href="#" id="btn-scroll-up" class="btn btn-small btn-inverse">
    <i class="icon-double-angle-up icon-only"></i>
</a>
<!-- 引入 -->
<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/ace-elements.min.js"></script>
<script src="static/js/ace.min.js"></script>

<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
<script type="text/javascript" src="static/js/bootstrap-datepicker.min.js"></script><!-- 日期框 -->
<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
<!-- 引入 -->
<script type="text/javascript" src="static/js/jquery.tips.js"></script><!--提示框-->
<script type="text/javascript">
    $(top.hangge());

    //检索
    function search() {
        top.jzts();
        $("#brokenScreenInsuranceForm").submit();
    }

    function operateDev(checkId, type) {
        var msg = "";
        if(type == 0){
            msg = "确定要核销么？";
        } else {
            msg = "确定要撤销核销么？"
        }
        bootbox.confirm(msg, function (result) {
            if (result) {
                top.jzts();
                var url = "<%=basePath%>brokenScreenInsurance/cancelVerification";
                var postParam = {"checkId": checkId,"type":type};
                $.post(url, postParam, function (data) {
                    top.Dialog.close();
                    if (data.code == 200) {
                        top.hangge();
                        $("#brokenScreenInsuranceForm").submit();
                    } else {
                        alert("操作失败:"+data.msg)
                    }
                });
            }
        })
    }


</script>

<script type="text/javascript">
    $(function () {
        //日期框
      /*  $('.date-picker').datepicker({autoclose: true});*/
        //下拉框
        $(".chzn-select").chosen();
        $(".chzn-select-deselect").chosen({allow_single_deselect: true});
        //复选框
       /* $('table th input:checkbox').on('click', function () {
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function () {
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });
        });*/
    });
</script>
</body>
</html>
